package com.lemon.smartsafety.http.service;

import android.content.Context;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.entity.safe.safe_manager.CompanySafeManageItemVo;
import com.lemon.smartsafety.http.UrlInfo;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;


/**
 * Created by Cooliean on 16/1/19.
 * 安全设置服务
 */
public class SafeManagerItemServices extends BaseHttpServices {

    private SafeManagerItemServices(Context context) {
        super(context);
    }

    public static SafeManagerItemServices init() {
        return new SafeManagerItemServices(IApplication.context());
    }


    /**
     * 获取安全管理设置的List
     *
     * @return
     */
    public SafeManagerItemServices getItemList(RefreshType type, int pageSize, int currentPage) {
        LemonRequestParams params = new LemonRequestParams();
        params.put("page_size", pageSize + "");
        params.put("current_page", currentPage + "");
        return getItemList(type, params);
    }

    /**
     * 获取安全管理设置的List
     *
     * @param params
     * @return
     */
    private SafeManagerItemServices getItemList(RefreshType type, LemonRequestParams params) {
        HandlerCallback<List<CompanySafeManageItemVo>> callback = new HandlerCallback<List<CompanySafeManageItemVo>>(EventTag.TAG_SAFE_MANAGER) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.SAFE_MANAGER_LIST);
        OkHttpUtils.post().url(serverUrl).tag(callback.getTag()).params(params).build().execute(callback);
        return this;
    }




    /**
     * 保存安全管理设置
     *
     * @return
     */
    public SafeManagerItemServices saveSafeManagerItemAction(LemonRequestParams params, boolean isEdit) {
        HandlerCallback<String> callback = new HandlerCallback<String>(EventTag.TAG_SAFE_MANAGER_SAVE_ACTION) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(isEdit ? UrlInfo.SAFE_MANAGER_ITEM_EDIT_ACTION : UrlInfo.SAFE_MANAGER_ITEM_ACTION);
        OkHttpUtils.post().url(serverUrl).tag(callback.getTag()).params(params).build().execute(callback);
        return this;
    }


}
